#region Microsoft Public License
/*
 * (c) Copyright Chenjun Wu. http://utablesdk.codeplex.com
 * 
 * This source is subject to the Microsoft Public License (Ms-PL).
 * Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
 * All other rights reserved.
 */
#endregion

﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UTable.Input.Keyboard
{
    public class KeyInputEventArgs: InputEventArgs
    {
        IKeyboard _device;
        Key _key;
        KeyStates _keyStates;
        ModifierKeys _modifierKeys;

        public KeyInputEventArgs(IKeyboard device, long timestamp, Key key): base(timestamp)
        {
            _device = device;
            _key = key;
            _keyStates = device.GetKeyStates(key);
            _modifierKeys = device.Modifiers;
        }
        // Summary:
        //     Gets the keyboard device associated with the input event.
        //
        // Returns:
        //     The logical keyboard device associated with the event.
        public IKeyboard KeyboardDevice 
        { 
            get { return _device; }
        }
        //
        // Summary:
        //     Gets a value that indicates whether the key referenced by the event is in
        //     the down state.
        //
        // Returns:
        //     true if the key is down; otherwise, false.
        public bool IsDown
        {
            get { return (this.KeyStates | KeyStates.Down) == KeyStates.Down; }
        }
        //
        // Summary:
        //     Gets a value that indicates whether the key referenced by the event is in
        //     the toggled state.
        //
        // Returns:
        //     true if the key is toggled; otherwise, false. There is no default value.
        public bool IsToggled
        {
            get { return (this.KeyStates | KeyStates.Toggled) == KeyStates.Toggled; }
        }
        //
        // Summary:
        //     Gets a value that indicates whether the key referenced by the event is in
        //     the up state.
        //
        // Returns:
        //     true if the key is up; otherwise, false. There is no default value.
        public bool IsUp
        {
            get { return !IsDown; }
        }
        //
        // Summary:
        //     Gets the keyboard key associated with the event.
        //
        // Returns:
        //     The System.Windows.Input.Key referenced by the event.
        public Key Key
        {
            get { return _key; }
        }
        //
        // Summary:
        //     Gets the state of the keyboard key associated with this event.
        //
        // Returns:
        //     The state of the key.
        public KeyStates KeyStates
        {
            get { return _keyStates; }
        }
    }
}
